import launch
import os
import yaml
import launch_ros
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.substitutions import Command, LaunchConfiguration
from ament_index_python.packages import get_package_share_directory

def generate_launch_description():
    ld = LaunchDescription()
    sdkeli_config = os.path.join(get_package_share_directory('sdkeli_ls_udp2'),'config','sdkeli_lidar.yaml')    
    with open(sdkeli_config,'r') as f:
        params = yaml.safe_load(f)["sdkeli_ls1207de"]["ros__parameters"]
        

    sdkeli_config2 = os.path.join(get_package_share_directory('sdkeli_ls_udp2'),'config','sdkeli_lidar2.yaml')
    with open(sdkeli_config2,'r') as o:
        
        params2 = yaml.safe_load(o)["sdkeli_ls1207de"]["ros__parameters2"]

    sdkeli_node = Node(
        namespace="sdkeli_ls1207de",
        package="sdkeli_ls_udp2",
        executable="sdkeli_ls1207de",
        parameters=[params],
        output='screen',
        remappings=[("scan","keli_scan")]
    )

  
    sdkeli_node2 = Node(
        namespace="sdkeli_ls1207de2",
        package="sdkeli_ls_udp2",
        executable="sdkeli_ls1207de",
        parameters=[params2],
        output='screen',
        remappings=[("scan","keli_scan2")]
    )

 
    ld.add_action(sdkeli_node)
    ld.add_action(sdkeli_node2)

    return ld
